package com.globallogic.vkulyk.SSHTool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jcraft.jsch.*;

public class FileCopier extends ActionExecutor {

	private final Logger logger = LoggerFactory
			.getLogger(FileCopier.class);

	public FileCopier(String hostArg, int portArg, String userArg,
			String passwordArg) {
		super(hostArg, portArg, userArg, passwordArg);
	}

	public ChannelSftp openSFTPChannel(Session session) {
		logger.debug("Opening SFTP channel..");
		Channel channel = null;
		ChannelSftp channelSFTP = null;
		try {
			channel = session.openChannel("sftp");
			channelSFTP = (ChannelSftp) channel;
			channel.connect();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return channelSFTP;
	}

	public void closeSFTPChannel(ChannelSftp channelSFTP) {
		logger.debug("Closing SFTP channel..");
		channelSFTP.disconnect();
	}

}
